#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+1;
	int n,m,s;
struct node{
	int parent = 0;
	vector<int>to;
	int depth;
}w[N];
int v[N];
int go[N][20];
void init(int r,int j){
	w[r].depth = j;
	v[r] = 1;
	int len = w[r].to.size();
	for(int i = 0;i<len;i++){
		if(!v[w[r].to[i]]){
			w[w[r].to[i]].parent = r;
			init(w[r].to[i],j+1);
		}
	}
}
int lca(int t1,int t2){
	if(w[t1].depth>w[t2].depth){
		int t = t1;
		t1 = t2;
		t2 = t;
	}
	while(w[t2].depth != w[t1].depth){
		int c = w[t2].depth - w[t1].depth;
		int d = log2(c);
		t2 = go[t2][d];
		d = c-d;
	}
	int newt1 = t1,newt2 = t2;
	while(newt1!=newt2){
		for(int i = log2(n);i>=0;i-- ){
			if(go[t1][i]){
				newt1 = go[t1][i];
				newt2 = go[t2][i];
				if(!i||newt1!=newt2){
					t1 = newt1;
					t2 = newt2;
					break;
				}
			}
			
		}
	}
	return t1;
}
int main(){
	int t1,t2;
	cin>>n>>m>>s;
	for(int i = 0;i<n-1;i++){
		cin>>t1>>t2;
		w[t1].to.push_back(t2);
		w[t2].to.push_back(t1);
	}
	init(s,1);

	for(int i = 0;1<<i <=n;i++){
		for(int j = 1;j<=n;j++){
			if(i==0 && w[j].parent)go[j][0] = w[j].parent;
			else if(go[go[j][i-1]][i-1])go[j][i] = go[go[j][i-1]][i-1];
		}
	}
	
	for(int i = 0;i<m;i++){
		cin>>t1>>t2;
		cout<<lca(t1,t2)<<endl;
	}
	return 0;
} 
